﻿using System;
using System.Collections.Generic;
using System.Data.SQLite;
using System.Linq;
using System.Text;

using NHibernate;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;
using System.IO;

namespace RushTracker.Core
{
    public class Installer
    {
        public void CreateDatabaseFile(string path)
        {
            SQLiteConnection.CreateFile(path);
        }

        public void CreateTables()
        {
            // create tables with nhibernate
            Configuration cfg = new Configuration();
            cfg.Properties["connection.connection_string"] = String.Format(cfg.Properties["connection.connection_string"], Site.Instance.ResolveUrl(Site.Instance.SQLiteDatabasePath));
            cfg.Configure();
            cfg.AddAssembly(this.GetType().Assembly);

            SchemaExport schema = new SchemaExport(cfg);
            //schema.SetOutputFile("c:\\tmpdb.txt");
            //schema.SetDelimiter(";");

            schema.Execute(false, true, false);
        }
    }
}
